import datetime
import os
import sys

from selenium import webdriver
from selenium.webdriver.chrome.service import Service


class Driver:
    driver = ""
    def __init__(self):
        ChromeIns = "E:\Environment\python3.10\chromedriver-win64\chromedriver.exe"
        self.driver = webdriver.Chrome(service=Service(ChromeIns))
        # self.driver.implicitly_wait(10)

    #创建屏幕截图
    def getScreenShot(self):
        #按日期分文件夹存放
        dirname = datetime.datetime.now().strftime("%Y-%m-%d")
        #判断dirname文件夹是否已经存在，不存在则创建文件夹
        if not os.path.exists("../images/"+dirname):
            os.mkdir("../images/"+dirname)

        #图片文件名：调用方法名+时间
        filename = sys._getframe().f_back.f_code.co_name+"-"+datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S")+".png"
        self.driver.save_screenshot("../images/"+dirname+"/"+filename)

QuestDriver = Driver()
# Driver().driver.get("https://www.baidu.com/")